﻿using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;
using DBUtility;//请先添加引用
namespace OracleDAL.Common
{
    /// <summary>
    /// 数据访问类COM_YYBM。
    /// </summary>
    public class COM_YYBM
    {
        public COM_YYBM()
        { }
        #region  成员方法

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string YYBM)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from COM_YYBM");
            strSql.Append(" where YYBM=:YYBM ");
            OracleParameter[] parameters = {
					new OracleParameter(":YYBM", OracleType.VarChar,50)};
            parameters[0].Value = YYBM;

            return OracleHelper.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(Model.Common.COM_YYBM model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into COM_YYBM(");
            strSql.Append("YYBM,YYMC,MATCHCODE,REMARK)");
            strSql.Append(" values (");
            strSql.Append(":YYBM,:YYMC,:MATCHCODE,:REMARK)");
            OracleParameter[] parameters = {
					new OracleParameter(":YYBM", OracleType.VarChar,20),
					new OracleParameter(":YYMC", OracleType.VarChar,40),
					new OracleParameter(":MATCHCODE", OracleType.VarChar,30),
					new OracleParameter(":REMARK", OracleType.VarChar,100)};
            parameters[0].Value = model.YYBM;
            parameters[1].Value = model.YYMC;
            parameters[2].Value = model.MATCHCODE;
            parameters[3].Value = model.REMARK;

            return OracleHelper.ExecuteSql(strSql.ToString(), parameters) > 0 ? true : false;
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.Common.COM_YYBM model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update COM_YYBM set ");
            strSql.Append("YYMC=:YYMC,");
            strSql.Append("MATCHCODE=:MATCHCODE,");
            strSql.Append("REMARK=:REMARK");
            strSql.Append(" where YYBM=:YYBM ");
            OracleParameter[] parameters = {
					new OracleParameter(":YYBM", OracleType.VarChar,20),
					new OracleParameter(":YYMC", OracleType.VarChar,40),
					new OracleParameter(":MATCHCODE", OracleType.VarChar,30),
					new OracleParameter(":REMARK", OracleType.VarChar,100)};
            parameters[0].Value = model.YYBM;
            parameters[1].Value = model.YYMC;
            parameters[2].Value = model.MATCHCODE;
            parameters[3].Value = model.REMARK;

            return OracleHelper.ExecuteSql(strSql.ToString(), parameters) > 0 ? true : false;
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteBYKey(string YYBM)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete COM_YYBM ");
            strSql.Append(" where YYBM=:YYBM ");
            OracleParameter[] parameters = {
					new OracleParameter(":YYBM", OracleType.VarChar,50)};
            parameters[0].Value = YYBM;

            return OracleHelper.ExecuteSql(strSql.ToString(), parameters) > 0 ? true : false;
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.Common.COM_YYBM GetModelBYKey(string YYBM)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select YYBM,YYMC,MATCHCODE,REMARK from COM_YYBM ");
            strSql.Append(" where YYBM=:YYBM ");
            OracleParameter[] parameters = {
					new OracleParameter(":YYBM", OracleType.VarChar,50)};
            parameters[0].Value = YYBM;

            Model.Common.COM_YYBM model = new Model.Common.COM_YYBM();
            DataSet ds = OracleHelper.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                model.YYBM = ds.Tables[0].Rows[0]["YYBM"].ToString();
                model.YYMC = ds.Tables[0].Rows[0]["YYMC"].ToString();
                model.MATCHCODE = ds.Tables[0].Rows[0]["MATCHCODE"].ToString();
                model.REMARK = ds.Tables[0].Rows[0]["REMARK"].ToString();
                return model;
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select YYBM,YYMC,MATCHCODE,REMARK ");
            strSql.Append(" FROM COM_YYBM ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return OracleHelper.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得网系数据列表
        /// </summary>
        /// <returns>OracleDataReader</returns>
        public OracleDataReader GetNet()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * from com_yybm where yybm like '90__' and yybm<>'9099' ");

            return OracleHelper.ExecuteReader(strSql.ToString());
        }

        #endregion  成员方法
    }
}

